import TicTacToe
import time


def show_main():
    print('   TicTacToe'.center(50))
    print()
    print('1.单人游戏'.center(50))
    print('2.双人游戏'.center(50))
    print()
    print('0.退出游戏'.center(50))


def help_():
    print('\n操作说明：输入对应的数字进行操作\n')
    print('1 | 2 | 3'.center(50))
    print('—————————'.center(50))
    print('4 | 5 | 6'.center(50))
    print('—————————'.center(50))
    print('7 | 8 | 9'.center(50))
    print()
    time.sleep(1)


def star_player():
    game = TicTacToe.TicTacToe()
    i = 1
    while game.winner() is None:
        print()
        print(game)
        pL = input(f'\n请玩家{i}操作：')
        try:
            if pL == '1': game.mark(0,0)
            elif pL == '2': game.mark(0,1)
            elif pL == '3': game.mark(0,2)
            elif pL == '4': game.mark(1,0)
            elif pL == '5': game.mark(1,1)
            elif pL == '6': game.mark(1,2)
            elif pL == '7': game.mark(2,0)
            elif pL == '8': game.mark(2,1)
            elif pL == '9': game.mark(2,2)
        except:
            continue
        i = i % 2 + 1
    print()
    print(game)
    print('玩家',1 if game.winner() == 'X' else 2,' WINNER!')


def star_com():
    pass


def main():
    while True:
        show_main()
        op = input('请输入操作')

        if op == '1':
            help_()
            star_player()
        elif op == '2':
            help_()
            star_com()
        elif op == '0':
            break


if __name__ == '__main__':
    main()
